//
//  FighterPrototypes.cpp
//  airfight
//
//  Created by aaron more on 12-8-27.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#include <iostream>
#include "FighterPrototypes.h"

FighterPrototypes* FighterPrototypes::s_SharedFighterPrototypes = NULL;

FighterPrototypes* FighterPrototypes::getInstance()
{
    static bool s_bFirstUseFighterPrototypes = true;
    if (NULL == s_SharedFighterPrototypes) {
        s_SharedFighterPrototypes = new FighterPrototypes();
        s_bFirstUseFighterPrototypes = false;
        s_SharedFighterPrototypes->init();
    }
    return s_SharedFighterPrototypes;

}

FighterPrototypes::FighterPrototypes()
{
    fighterPrototype_Dict = NULL;
}

bool FighterPrototypes::init()
{
    fighterPrototype_Dict = CCDictionary::create();
    fighterPrototype_Dict->retain();
    return true;
}

FighterPrototypes::~FighterPrototypes()
{
    CC_SAFE_RELEASE(fighterPrototype_Dict);
}

void FighterPrototypes::addFighter(Fighter* p_fighter)
{
    int fighter_id = p_fighter->getFighterId();
    fighterPrototype_Dict->setObject(p_fighter, fighter_id);
}

Fighter* FighterPrototypes::getFighterByID(int p_id)
{
    CCObject* tmp = fighterPrototype_Dict->objectForKey(p_id);
    
    if(tmp){
        return (Fighter*)tmp;
    }else{
        return NULL;
    }
}